package com.sgb.kjwl.view.ui.adapter.self.packers;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.SelfEmploymentApplyEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class SelfEmploymentApplyAdapter extends BaseRecycleAdapter<SelfEmploymentApplyEntity> {

    public SelfEmploymentApplyAdapter(Context context, List<SelfEmploymentApplyEntity> data) {
        super(context, R.layout.item_self_employment_apply, data);
    }

    @Override
    public void convert(ItemViewHolder holder, SelfEmploymentApplyEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView userInfo = holder.itemView.findViewById(R.id.user_info);
        userInfo.setText(String.format("%s  |  %s", entity.getContact(), entity.getContactPhone()));
        holder.itemView.findViewById(R.id.btn_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.delete(entity.getNo());
            }
        });
        holder.itemView.findViewById(R.id.btn_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.edit(entity.getNo());
            }
        });
    }

    public interface ItemOnClickListener {
        void delete(String no);

        void edit(String no);
    }

    private ItemOnClickListener listener;

    public void setListener(ItemOnClickListener listener) {
        this.listener = listener;
    }
}